package com.toggery.POS.service;

import com.toggery.POS.dao.UserMapper;
import com.toggery.POS.entity.User;
import com.toggery.POS.entity.UserRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserMapper mapper ;

    public List<UserRecord> findAllWithinRole(){
        return  mapper.queryForList();
    }
    public boolean save(User user){
        if(mapper.findById(user.getId())==null){
            mapper.insert(user);
            return true;
        }else {
            return false;
        }

    }
    public boolean updateUser(User user){
        if(mapper.updateByPrimaryKey(user)>0){
            return true;
        }else {
            return false;
        }
    }
    public boolean deleteByid(int id){
        if(mapper.deleteByPrimaryKey(id+"")>0){
            return true;
        }else {
            return false;
        }
    }
    public User findById(int id){
        return mapper.findById(id+"");
    }
//    精确查询
    public User findByName(String name){
        return mapper.findByName(name);
    }
//    模糊查询
    public List<User> findLikeName(String name){
        //加上通配符
        name = "%"+name+"%";
        return mapper.findLikeName(name);
    }
}
